<?php

class CGamefbscence extends Zend_Db_Table
{

    protected $_name;

    protected $_primary;

    public function _setup()
    {

        $this->_name=R_PRE."game_fb_scene";

        $this->_primary="id";

        parent::_setup();

    }

    public function createFbscence($data)
    {

        $this->insert($data);

        return true;

    }

    public function editFbscence($id,$data)
        {
		$db=$this->getAdapter();

		$where = $db->quoteInto('id = ?', $id);

		$rows_affected=$db->update($this->_name,$data,$where);

		if($rows_affected!=1){

			return false;

		}else{

			return true;

		}
        }

    public function getscencedetail($id){
        
        $db=$this->getAdapter();
        $select = $db->select();

        $select->from($this->_name,'*');

        $join_table = R_PRE."game_fb_teams";
        $select->joinLeft($join_table." AS A", "A.id = $this->_name.team_one", array('name_one'=>'A.name','itemid_one'=>'A.itemid'));
        $select->joinLeft($join_table." AS B", "B.id = $this->_name.team_two", array('name_two'=>'B.name','itemid_two'=>'B.itemid'));

        $select->where($this->_name.'.id = ? ',$id);
        return $db->fetchAll($select);

    }

    public function getscences($from,$counts,$where=''){

        $db=$this->getAdapter();
        $select = $db->select();

        $select->from($this->_name,'*');

        $select->order("add_time DESC");
        $join_table = R_PRE."game_fb_teams";
        $select->joinLeft($join_table." AS A", "A.id = $this->_name.team_one", array('name_one'=>'A.name','itemid_one'=>'A.itemid'));
        $select->joinLeft($join_table." AS B", "B.id = $this->_name.team_two", array('name_two'=>'B.name','itemid_two'=>'B.itemid'));

        if($where!=''){

			$select->where($where);

	}

        if($counts!=0){

            $select->limit($counts, $from);

        }
        return $db->fetchAll($select);

    }


    public function getAllfbscence($where=''){

            $db=$this->getAdapter();

            $select = $db->select();

            $select->from($this->_name,'COUNT(*)');

            if($where!=''){

                    $select->where($where);

            }

            return $db->fetchOne($select);

    }

    public function delfbscence($scenceidArray){

            $db=$this->getAdapter();

            $scenceidString=join(',',$scenceidArray);
            $result=$db->query("DELETE FROM $this->_name WHERE id IN ($scenceidString)");

            return $result;

    }
}